package com.sams.controller;

import com.github.pagehelper.PageInfo;
//import com.sams.entity.Outerinfo;
import com.sams.service.OuterinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RequestMapping("/Outerinfo")
@Controller
public class OuterinfoController {

	/*
	 * @Autowired public OuterinfoService outerinfoService;
	 * 
	 * @ResponseBody
	 * 
	 * @RequestMapping(value="/add",method = RequestMethod.POST) public String
	 * add(@RequestPart("file") MultipartFile multipartFile, Outerinfo
	 * outerinfo,HttpServletRequest request){ // Outerinfo outerinfo=new
	 * Outerinfo(); String medianame = request.getParameter("medianame");
	 * outerinfo.setMedianame(medianame); String[] mediatypes =
	 * request.getParameterValues("mediatype"); for (String s: mediatypes){
	 * outerinfo.setMedianame(s); } String[] levels =
	 * request.getParameterValues("level"); for (String a: levels){
	 * outerinfo.setLevel(a); } String title = request.getParameter("title");
	 * outerinfo.setTitle(title); String titleno = request.getParameter("titleno");
	 * outerinfo.setTitleno(Integer.parseInt(titleno)); String num =
	 * request.getParameter("num"); outerinfo.setNum(Integer.parseInt(num)); String
	 * page = request.getParameter("page");
	 * outerinfo.setPage(Integer.parseInt(page)); String url =
	 * request.getParameter("url"); outerinfo.setUrl(url);
	 * 
	 * 
	 * //上传的文件地址 String realPath =
	 * request.getSession().getServletContext().getRealPath("/upload");
	 * System.out.println("realPath = " + realPath); //获取文件名 String filename =
	 * multipartFile.getOriginalFilename(); //获取文件后缀名 String substring =
	 * filename.substring(filename.lastIndexOf(".") + 1); //给文件取先的名字 String
	 * newFilename = String.valueOf(System.currentTimeMillis() + "." + substring);
	 * outerinfo.setFile("upload/"+newFilename); File dir=new
	 * File(realPath,newFilename); outerinfoService.add(outerinfo); if
	 * (!dir.exists()){ dir.mkdirs(); } try { multipartFile.transferTo(dir); } catch
	 * (IOException e) { e.printStackTrace(); }
	 * 
	 * return "forward:/Outerinfo/list"; }
	 * 
	 * @RequestMapping("/list") public String list(Integer currentPage, Model
	 * model){ if (currentPage==null||currentPage==0){ currentPage=1; }
	 * PageInfo<Outerinfo> outerinfoPageInfo =
	 * outerinfoService.listDepart(currentPage);
	 * System.out.println("outerinfoPageInfo = " + outerinfoPageInfo);
	 * model.addAttribute("lists",outerinfoPageInfo);
	 * 
	 * return "outerInfo"; }
	 * 
	 * @RequestMapping("/update") public String update(Outerinfo outerinfo){ return
	 * "111"; } //可以让时间为空
	 * 
	 * @InitBinder public void initBinder(WebDataBinder binder){ SimpleDateFormat
	 * dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	 * dateFormat.setLenient(false); binder.registerCustomEditor(Date.class,new
	 * CustomDateEditor(dateFormat,true));
	 * 
	 * }
	 */
}
